//
//  RYAvatarCell.swift
//  App_Profile
//
//  Created by 蒋晨成 on 2022/2/9.
//

import Adaptor
import App_Common_Views
import Foundation
import Kingfisher
import UICore
import UIKit

public class RYAvatarCell: RYTitleCell {
    lazy var avatarView: AvatarView = {
        let avatarView = AvatarView(action: nil, option: .init(cornerRadius: 20, border: false))
        return avatarView
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    @available(*, unavailable)
    required init?(coder _: NSCoder) { fatalError("init(coder:) has not been implemented") }

    override func reusableCell(_ cellModel: RYBaseCellModel) {
        super.reusableCell(cellModel)
        guard let cellModel = cellModel as? RYAvatarCellModel else { return }
        avatarView.set(url: cellModel.imageUrl, placeholder: cellModel.placeHolder)
    }
}

private extension RYAvatarCell {
    func setupUI() {
        avatarView.x.add(to: contentView).snp.makeConstraints {
            $0.trailing.equalToSuperview().offset(-20)
            $0.centerY.equalToSuperview()
            $0.width.height.equalTo(40)
        }
    }
}
